<?php
/* 影院管理
* @Author: Jerry-chen
* @Date:   2014-07-08 17:16:39
* @Last Modified time: 2014-07-23 19:17:01
* @Last Modified by: Jerry-chen<uranusbill@163.com>
* @ Copyright (c) 2014 http://www.cooldreamer.com All rightsreserved.
*/
class CinemaControl extends CommonControl
{
	public $model;
	public $seatmodel;
	public function __auto()
	{
		$this->model = K('cinema');
		$this->seatmodel = K('Seat');
	}
	/**
	 * [index 列表]
	 * @return [type] [description]
	 */
	public function index()
	{
		// 查出所有的影院数据
		$cinemaData = $this->model->get_all();
		
		// P($cinemaData);
		// die;
		// 分配变量
		$this->assign('cinemaData',$cinemaData);

		$this->display();
	}
	/**
	 * [add 添加数据]
	 */
	public function add()
	{
		if(IS_POST)
		{
			// p(Q('post.'));
			// die;
			$this->model->add_();
			$this->success('添加成功','index');
		}
		$this->display();
	}
	/**
	 * [add_seat 座位管理]
	 */
	public function add_seat()
	{
		// 根据GET传参查出所属的影院
		// p(Q('get.'));die;
		//所属影院
		$cinemaname = Q('get.cinemaname');
		// p($cinemaname);die;
		$this->assign('cinemaname',$cinemaname);
		if(IS_POST)
		{
			$result = $this->seatmodel->add_();
			if(!$result){
				$this->error('添加错误','index');
			}
			$this->success('添加成功','index');
		}

		$this->display();
	}
	public function edit()
	{
		//获得旧的数据
		$cinemaid = Q('get.cinemaid');
		//组合WHERE 条件
		$where = array('cinemaid'=>$cinemaid);
		$oldData = $this->model->get_one($where);
		// p($oldData);die;
		//分配数据
		$this->assign('oldData',$oldData);
		// p(Q('get.'));die;
		if(IS_POST)
		{
			$cinemaid = Q('post.cinemaid');
			$this->model->edit_($cinemaid);
			$this->success('修改成功','index');
		}
		$this->display();
	}
	/**
	 * [del_ 删除]
	 * @return [type] [description]
	 */
	public function del()
	{
		$cinemaid = Q('get.cinemaid');
		$where = array('cinemaid'=>$cinemaid);
		$this->model->del_($where);
		$this->success('删除成功','index');
	}
	/**
	 * [seat_list 座位列表]
	 * @return [type] [description]
	 */
	public function seat_list()
	{
		//获得GET参数
		$cinemaid = Q('get.cinemaid');
		// 查出WHERE条件相关的所有
		$where = array('cinemaid'=>$cinemaid);
		$seatData = $this->seatmodel->get_all_($where);
		// 分配变量 
		$this->assign('seatData',$seatData);
		// 查出所属影院
		$cinemaname = $this->model->get_one($where);
		$this->assign('cinemaname',$cinemaname);

		// p($cinemaname);die;


		$this->display();
	 }
	 /**
	  * [edit_set 修改座位列表]
	  * @return [type] [description]
	  */
	public function edit_seat()
	{
		if(IS_POST)
		{
			$result = K('Seat')->edit(array('seatid'=>Q('post.seatid')));
			if($result){
				$this->success('修改成功','index');
			}else{
				$this->error('修改失败','index');
			}
		}
		// 根据获得的SEATID，查出相关数据
		$seatid = Q('get.seatid');
		$seatdata = current(K('Seat')->get_all_(array('seatid'=>$seatid)));
		// p($seatdata);
		$this->assign('seatdata',$seatdata);
		//根据SEAT查出，CINEMA信息
		$cinema = current(K('Cinema')->get_all(array('cinemaid'=>$seatdata['cinemaid'])));
		$this->assign('cinema',$cinema);
		// p($cinema);
		// die;

		$this->display();
	}
	/**
	 * [del_seat 删除数据]
	 * @return [type] [description]
	 */
	public function del_seat()
	{
		
		$result = K('Seat')->del_(array('seatid'=>Q('get.seatid')));
		if($result){
				$this->success('删除成功','index');
			}else{
				$this->error('删除失败','index');
			}
	}
}

?>
